package config;

import util.IniHelper;

import java.io.File;
import java.io.IOException;

/**
 * @author wyl
 */
public class AppConfig {
    private static final String CONFIG_PATH = "./res/config.ini";
    private static final String WS_SERVER_URL_KEY = "server_url";
    private static String WS_SERVER_URL = "";

    public static void initConfig() throws Exception {
        File file = new File(CONFIG_PATH);
        if (!file.exists()) {
            file.getParentFile().mkdirs();
            file.createNewFile();
            setNotes("在[" + WS_SERVER_URL_KEY + "]项目填写您的ws服务器地址");
            setServerConfig("");
        } else {
            WS_SERVER_URL = IniHelper.readIniFile(CONFIG_PATH).get(WS_SERVER_URL_KEY);
        }
    }

    public static String getServerUrl() {
        return WS_SERVER_URL;
    }

    public static void setServerConfig(String url) throws Exception {
        IniHelper.setIni(CONFIG_PATH, "server", WS_SERVER_URL_KEY, url);
    }

    public static void setNotes(String notes) throws Exception {
        IniHelper.setIni(CONFIG_PATH, "notes", "ConfigurationDescription", notes);
    }

}
